package edu.java.lectures.lec14.collections.usage;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

public class ListTest {

    public static void main(String[] args) {
	// BAD PRACTICE
	// ArrayList<String> myStringList = new ArrayList<String>();
	// LinkedList<String> myStringList = new LinkedList<String>();

	List<String> myStringList = new ArrayList<String>();
	doSthng1(myStringList);
	doSthng2(myStringList);
	doSthng3(myStringList);

	myStringList.add("Pencho");
	// myStringList.add(new Integer(2)); // impossible
	myStringList.add("tropcho");
	// myStringList.add(4, "Mincho"); // IndexOutOfBoundsException
	myStringList.add(1, "Mincho");
	System.out.println(myStringList);
	for (String myString : myStringList) {
	    System.out.println(myString);
	}
	System.out.println(myStringList.contains("Pencho"));
	System.out.println(myStringList.contains("pencho"));
	System.out.println(myStringList.get(2));
	// System.out.println(myStringList.get(3));
	System.out.println(myStringList.remove(0));
	System.out.println(myStringList);
	System.out.println(myStringList.contains("Pencho"));
	System.out.println(myStringList.remove("Mincho22"));
	System.out.println(myStringList);
	System.out.println(myStringList.indexOf("Mincho"));
	System.out.println(myStringList.indexOf("Tropcho"));
	System.out.println(myStringList.set(1, "Tropcho"));
	System.out.println(myStringList);
	System.out.println(myStringList.toArray());

	Object[] myObjArr = myStringList.toArray();
	String[] myStrArr = new String[myObjArr.length];
	for (int i = 0; i < myObjArr.length; i++) {
	    myStrArr[i] = (String) myObjArr[i];
	}
	
	Collections.synchronizedList(myStringList); // do NOT use Vector

	// String[] myStringListArrr = new String[myStringList.size()];
	String[] myStringListArrr = myStringList
		.toArray(new String[myStringList.size()]);

	System.out.println(myStringList.size());

	List<Integer> myIntList = new LinkedList<Integer>();
	myIntList.add(new Integer(5));
	myIntList.add(4); // boxing -> add(new Integer(4))
    }

    public static void doSthng1(List<String> strList) {

    }

    public static void doSthng2(List<String> strList) {

    }

    public static void doSthng3(List<String> strList) {

    }
}
